const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

var j = 0;
if (cluster.isMaster) {
    console.log('there are ' + numCPUs + "'s cpus")
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', (worker, code, signal) => {
    console.log(`worker ${worker.process.pid} died`);
  });
} else {
    console.log(++j);
  // Workers can share any TCP connection
  // In this case it is an HTTP server
  http.createServer((req, res) => {
    res.writeHead(200);
    res.end('hello world\n');
    console.log('haha')
  }).listen(8000);
}
